﻿// Decompiled with JetBrains decompiler
// Type: TaleWorlds.CampaignSystem.Issues.SmugglersIssueBehavior
// Assembly: TaleWorlds.CampaignSystem, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null
// MVID: E85F8C15-4DF6-4E9C-A58A-29177E40D07A
// Assembly location: D:\steam\steamapps\common\Mount & Blade II Bannerlord\bin\Win64_Shipping_Client\TaleWorlds.CampaignSystem.dll

using Helpers;
using System;
using System.Collections.Generic;
using System.Linq;
using TaleWorlds.CampaignSystem.Actions;
using TaleWorlds.CampaignSystem.CharacterDevelopment;
using TaleWorlds.CampaignSystem.Conversation;
using TaleWorlds.CampaignSystem.Conversation.Persuasion;
using TaleWorlds.CampaignSystem.Encounters;
using TaleWorlds.CampaignSystem.Extensions;
using TaleWorlds.CampaignSystem.Map;
using TaleWorlds.CampaignSystem.MapEvents;
using TaleWorlds.CampaignSystem.Party;
using TaleWorlds.CampaignSystem.Party.PartyComponents;
using TaleWorlds.CampaignSystem.Roster;
using TaleWorlds.CampaignSystem.Settlements;
using TaleWorlds.Core;
using TaleWorlds.Library;
using TaleWorlds.Localization;
using TaleWorlds.ObjectSystem;
using TaleWorlds.SaveSystem;

#nullable disable
namespace TaleWorlds.CampaignSystem.Issues
{
  public class SmugglersIssueBehavior : CampaignBehaviorBase
  {
    private const IssueBase.IssueFrequency SmugglersIssueFrequency = IssueBase.IssueFrequency.Rare;

    public override void RegisterEvents()
    {
      CampaignEvents.OnCheckForIssueEvent.AddNonSerializedListener((object) this, new Action<Hero>(this.OnCheckForIssue));
    }

    private void OnCheckForIssue(Hero hero)
    {
      Campaign.Current.IssueManager.AddPotentialIssueData(hero, this.ConditionsHold(hero) ? new PotentialIssueData(new PotentialIssueData.StartIssueDelegate(this.OnStartIssue), typeof (SmugglersIssueBehavior.SmugglersIssue), IssueBase.IssueFrequency.Rare) : new PotentialIssueData(typeof (SmugglersIssueBehavior.SmugglersIssue), IssueBase.IssueFrequency.Rare));
    }

    private bool ConditionsHold(Hero issueGiver)
    {
      return issueGiver.IsLord && issueGiver.Clan != Clan.PlayerClan && (double) issueGiver.GetRelationWithPlayer() >= -10.0 && issueGiver.Clan.Settlements.AnyQ<Settlement>((Func<Settlement, bool>) (settlement => settlement.Owner == issueGiver && settlement.IsTown));
    }

    private IssueBase OnStartIssue(in PotentialIssueData pid, Hero issueOwner)
    {
      return (IssueBase) new SmugglersIssueBehavior.SmugglersIssue(issueOwner);
    }

    public override void SyncData(IDataStore dataStore)
    {
    }

    public class SmugglersIssue : IssueBase
    {
      [SaveableField(1)]
      private readonly Settlement _targetSettlement;
      [SaveableField(2)]
      private readonly Settlement _originSettlement;
      private const int IssueDuration = 30;
      private const int QuestTimeLimit = 20;
      private const int CompanionRequiredSkillLevel = 150;
      private const int AlternativeSolutionMinimumTroopLevel = 2;
      private const int SuccessRelationBonus = 10;
      private const int SuccessSecurityBonus = 10;
      private const int TroopsRequiredForQuest = 10;

      internal static void AutoGeneratedStaticCollectObjectsSmugglersIssue(
        object o,
        List<object> collectedObjects)
      {
        ((MBObjectBase) o).AutoGeneratedInstanceCollectObjects(collectedObjects);
      }

      protected override void AutoGeneratedInstanceCollectObjects(List<object> collectedObjects)
      {
        base.AutoGeneratedInstanceCollectObjects(collectedObjects);
        collectedObjects.Add((object) this._targetSettlement);
        collectedObjects.Add((object) this._originSettlement);
      }

      internal static object AutoGeneratedGetMemberValue_targetSettlement(object o)
      {
        return (object) ((SmugglersIssueBehavior.SmugglersIssue) o)._targetSettlement;
      }

      internal static object AutoGeneratedGetMemberValue_originSettlement(object o)
      {
        return (object) ((SmugglersIssueBehavior.SmugglersIssue) o)._originSettlement;
      }

      public override bool IsThereAlternativeSolution => true;

      public override bool IsThereLordSolution => false;

      protected override bool IssueQuestCanBeDuplicated => false;

      protected override int RewardGold
      {
        get => (int) (750.0 + 3000.0 * (double) this.IssueDifficultyMultiplier);
      }

      public SmugglersIssue(Hero issueOwner)
        : base(issueOwner, CampaignTime.DaysFromNow(30f))
      {
        SmugglersIssueBehavior.SmugglersIssue smugglersIssue = this;
        this._targetSettlement = issueOwner.Clan.Settlements.FirstOrDefaultQ<Settlement>((Func<Settlement, bool>) (settlement => settlement.Owner == issueOwner && settlement.IsTown));
        this._originSettlement = SettlementHelper.FindNearestTown((Func<Settlement, bool>) (town => town != smugglersIssue._targetSettlement), (IMapPoint) this._targetSettlement);
      }

      public override TextObject IssueBriefByIssueGiver
      {
        get
        {
          TextObject briefByIssueGiver = new TextObject("{=bZQQPtJr}{TARGET_SETTLEMENT} has a problem with smugglers. We depend on tariffs for income. People complain, but if we don't collect, then there's no money to keep up the walls and pay the garrison, and believe me if an enemy army came around and pillaged the place because it wasn't defended properly, they'd complain about that too.");
          briefByIssueGiver.SetTextVariable("TARGET_SETTLEMENT", this._targetSettlement.Name);
          return briefByIssueGiver;
        }
      }

      public override TextObject IssueAcceptByPlayer => new TextObject("{=088shjNR}Go on...");

      public override TextObject IssueAlternativeSolutionExplanationByIssueGiver
      {
        get
        {
          TextObject explanationByIssueGiver = new TextObject("{=84x0gfUf}I would prefer it if you attended to this yourself. But if you have any companions who can handle a force of {REQUIRED_TROOP_AMOUNT} men, one of them can take care of it.");
          explanationByIssueGiver.SetTextVariable("REQUIRED_TROOP_AMOUNT", this.GetTotalAlternativeSolutionNeededMenCount());
          return explanationByIssueGiver;
        }
      }

      public override TextObject IssueAlternativeSolutionAcceptByPlayer
      {
        get
        {
          return new TextObject("{=tbR8HmFc}No need to worry, I will have my men attend to the matter immediately.");
        }
      }

      public override TextObject IssueQuestSolutionExplanationByIssueGiver
      {
        get
        {
          TextObject explanationByIssueGiver = new TextObject("{=9jJ0QQYm}I think the reason we have it so bad here is because one gang in particular has good contacts both in {TARGET_SETTLEMENT} and in {ORIGIN_SETTLEMENT}. They've so far managed to elude me, but if you patrol the area between the two cities, you might have better luck. And look - I'd prefer it if you brought them to justice, but if you can persuade them to move elsewhere, I'd settle for that too.");
          explanationByIssueGiver.SetTextVariable("TARGET_SETTLEMENT", this._targetSettlement.Name);
          explanationByIssueGiver.SetTextVariable("ORIGIN_SETTLEMENT", this._originSettlement.Name);
          return explanationByIssueGiver;
        }
      }

      public override TextObject IssueQuestSolutionAcceptByPlayer
      {
        get => new TextObject("{=acqSONrT}I will handle these smugglers myself.");
      }

      public override TextObject IssueAlternativeSolutionResponseByIssueGiver
      {
        get => new TextObject("{=g8qb3Ame}Thank you.");
      }

      public override TextObject IssueDiscussAlternativeSolution
      {
        get
        {
          return new TextObject("{=RZdL3Mbt}I'm sure your men will take care of those smugglers in no time. I await your good news.");
        }
      }

      public override TextObject Title
      {
        get
        {
          TextObject title = new TextObject("{=Gop9Khfk}Smugglers of {TARGET_CITY}");
          title.SetTextVariable("TARGET_CITY", this._targetSettlement.Name);
          return title;
        }
      }

      public override TextObject Description
      {
        get
        {
          TextObject to = new TextObject("{=pS8Iqeja}{QUEST_GIVER.LINK} is having problems with smugglers in {ORIGIN_CITY}. {?QUEST_GIVER.GENDER}She{?}He{\\?} said that they get their goods from {TARGET_CITY}.");
          to.SetTextVariable("TARGET_CITY", this._targetSettlement.Name);
          to.SetTextVariable("ORIGIN_CITY", this._originSettlement.Name);
          to.SetCharacterProperties("QUEST_GIVER", this.IssueOwner.CharacterObject);
          return to;
        }
      }

      protected override TextObject AlternativeSolutionStartLog
      {
        get
        {
          TextObject to = new TextObject("{=bGERUWEr}{ISSUE_GIVER.LINK} {?ISSUE_GIVER.GENDER}lady{?}lord{\\?} of {TARGET_SETTLEMENT} told you that {?ISSUE_GIVER.GENDER}she{?}he{\\?} has been having issues with smugglers running between {TARGET_SETTLEMENT} and {ORIGIN_SETTLEMENT}. You decided to send {COMPANION.LINK} with {TROOP_COUNT} men to find the smugglers. They should return after {RETURN_DAYS} days.");
          to.SetCharacterProperties("ISSUE_GIVER", this.IssueOwner.CharacterObject);
          to.SetCharacterProperties("COMPANION", this.AlternativeSolutionHero.CharacterObject);
          to.SetTextVariable("TARGET_SETTLEMENT", this._targetSettlement.EncyclopediaLinkWithName);
          to.SetTextVariable("ORIGIN_SETTLEMENT", this._originSettlement.EncyclopediaLinkWithName);
          to.SetTextVariable("TROOP_COUNT", this.AlternativeSolutionSentTroops.TotalManCount - 1);
          to.SetTextVariable("RETURN_DAYS", this.GetTotalAlternativeSolutionDurationInDays());
          return to;
        }
      }

      public override TextObject IssueAlternativeSolutionSuccessLog
      {
        get
        {
          TextObject to = new TextObject("{=QhyB7MX0}Your companion {COMPANION.LINK} and your men return with the news of their success. They dispersed the smugglers as promised to {QUEST_GIVER.LINK}.");
          to.SetCharacterProperties("COMPANION", this.AlternativeSolutionHero.CharacterObject);
          to.SetCharacterProperties("QUEST_GIVER", this.IssueOwner.CharacterObject);
          return to;
        }
      }

      public override TextObject IssueAlternativeSolutionFailLog
      {
        get
        {
          TextObject to = new TextObject("{=ExRIMXDV}Your men failed to get rid of the smugglers as you told {QUEST_GIVER.LINK} you would do.");
          to.SetCharacterProperties("QUEST_GIVER", this.IssueOwner.CharacterObject);
          return to;
        }
      }

      protected override int CompanionSkillRewardXP
      {
        get => 500 + (int) (1000.0 * (double) this.IssueDifficultyMultiplier);
      }

      public override int AlternativeSolutionBaseNeededMenCount
      {
        get => (int) (10.0 + 20.0 * (double) this.IssueDifficultyMultiplier);
      }

      protected override int AlternativeSolutionBaseDurationInDaysInternal
      {
        get => (int) (7.0 + 10.0 * (double) this.IssueDifficultyMultiplier);
      }

      public override IssueBase.AlternativeSolutionScaleFlag AlternativeSolutionScaleFlags
      {
        get => (IssueBase.AlternativeSolutionScaleFlag) (4 | 8);
      }

      public override (SkillObject, int) GetAlternativeSolutionSkill(Hero hero)
      {
        List<SkillObject> solutionMeleeSkills = QuestHelper.GetAlternativeSolutionMeleeSkills();
        solutionMeleeSkills.Add(DefaultSkills.Scouting);
        return (solutionMeleeSkills.MaxBy<SkillObject, int>((Func<SkillObject, int>) (skill => hero.GetSkillValue(skill))), 150);
      }

      public override bool AlternativeSolutionCondition(out TextObject explanation)
      {
        explanation = TextObject.Empty;
        return QuestHelper.CheckRosterForAlternativeSolution(MobileParty.MainParty.MemberRoster, this.GetTotalAlternativeSolutionNeededMenCount(), ref explanation, 2);
      }

      protected override void AlternativeSolutionEndWithSuccessConsequence()
      {
        GiveGoldAction.ApplyBetweenCharacters((Hero) null, Hero.MainHero, this.RewardGold);
        this.RelationshipChangeWithIssueOwner = 10;
        this._targetSettlement.Town.Security += 10f;
      }

      public override bool DoTroopsSatisfyAlternativeSolution(
        TroopRoster troopRoster,
        out TextObject explanation)
      {
        explanation = TextObject.Empty;
        return QuestHelper.CheckRosterForAlternativeSolution(troopRoster, this.GetTotalAlternativeSolutionNeededMenCount(), ref explanation, 2);
      }

      public override IssueBase.IssueFrequency GetFrequency() => IssueBase.IssueFrequency.Rare;

      public override bool IssueStayAliveConditions()
      {
        return this.IssueOwner.IsAlive && this._targetSettlement.Owner == this.IssueOwner && (double) this._targetSettlement.Town.Security < 80.0;
      }

      protected override bool CanPlayerTakeQuestConditions(
        Hero issueGiver,
        out IssueBase.PreconditionFlags flag,
        out Hero relationHero,
        out SkillObject skill)
      {
        flag = IssueBase.PreconditionFlags.None;
        relationHero = issueGiver;
        skill = (SkillObject) null;
        if ((double) issueGiver.GetRelationWithPlayer() < -10.0)
          flag |= IssueBase.PreconditionFlags.Relation;
        if (FactionManager.IsAtWarAgainstFaction(issueGiver.MapFaction, Hero.MainHero.MapFaction))
          flag |= IssueBase.PreconditionFlags.AtWar;
        if (MobileParty.MainParty.MemberRoster.TotalManCount <= 10)
          flag |= IssueBase.PreconditionFlags.NotEnoughTroops;
        return flag == IssueBase.PreconditionFlags.None;
      }

      protected override float GetIssueEffectAmountInternal(IssueEffect issueEffect)
      {
        if (issueEffect == DefaultIssueEffects.SettlementLoyalty)
          return -0.1f;
        return issueEffect == DefaultIssueEffects.SettlementSecurity ? -0.5f : 0.0f;
      }

      protected override void CompleteIssueWithTimedOutConsequences()
      {
      }

      protected override void OnGameLoad()
      {
      }

      protected override QuestBase GenerateIssueQuest(string questId)
      {
        return (QuestBase) new SmugglersIssueBehavior.SmugglersIssueQuest(questId, this.IssueOwner, this._targetSettlement, this._originSettlement, this.IssueDifficultyMultiplier, CampaignTime.DaysFromNow(20f), this.RewardGold);
      }

      protected override void HourlyTick()
      {
      }
    }

    public class SmugglersIssueQuest : QuestBase
    {
      [SaveableField(1)]
      private readonly Settlement _targetSettlement;
      [SaveableField(2)]
      private readonly Settlement _originSettlement;
      [SaveableField(3)]
      private MobileParty _smugglerParty;
      [SaveableField(4)]
      private readonly float _issueDifficulty;
      [SaveableField(5)]
      private int _smugglerSettlementWaitCounter;
      private const int FailRelationPenalty = -10;
      private const int SuccessRelationBonus = 10;
      private const int SuccessSecurityBonus = 10;
      private const int MaxSmugglerPartySize = 35;
      private const int MinSmugglerPartySize = 15;
      private const int SmugglerPartyWaitingHours = 4;
      private const string SmugglerPersuasionDialogToken = "start_smugglers_persuasion";
      private readonly string[] _possibleSmuggledItems = new string[4]
      {
        "jewelry",
        "spice",
        "velvet",
        "fur"
      };
      private PersuasionTask _task;
      private const PersuasionDifficulty Difficulty = PersuasionDifficulty.MediumHard;

      internal static void AutoGeneratedStaticCollectObjectsSmugglersIssueQuest(
        object o,
        List<object> collectedObjects)
      {
        ((MBObjectBase) o).AutoGeneratedInstanceCollectObjects(collectedObjects);
      }

      protected override void AutoGeneratedInstanceCollectObjects(List<object> collectedObjects)
      {
        base.AutoGeneratedInstanceCollectObjects(collectedObjects);
        collectedObjects.Add((object) this._targetSettlement);
        collectedObjects.Add((object) this._originSettlement);
        collectedObjects.Add((object) this._smugglerParty);
      }

      internal static object AutoGeneratedGetMemberValue_targetSettlement(object o)
      {
        return (object) ((SmugglersIssueBehavior.SmugglersIssueQuest) o)._targetSettlement;
      }

      internal static object AutoGeneratedGetMemberValue_originSettlement(object o)
      {
        return (object) ((SmugglersIssueBehavior.SmugglersIssueQuest) o)._originSettlement;
      }

      internal static object AutoGeneratedGetMemberValue_smugglerParty(object o)
      {
        return (object) ((SmugglersIssueBehavior.SmugglersIssueQuest) o)._smugglerParty;
      }

      internal static object AutoGeneratedGetMemberValue_issueDifficulty(object o)
      {
        return (object) ((SmugglersIssueBehavior.SmugglersIssueQuest) o)._issueDifficulty;
      }

      internal static object AutoGeneratedGetMemberValue_smugglerSettlementWaitCounter(object o)
      {
        return (object) ((SmugglersIssueBehavior.SmugglersIssueQuest) o)._smugglerSettlementWaitCounter;
      }

      private int BribeAmount => (int) ((double) this.RewardGold * 0.75);

      private int SmugglerPartySize
      {
        get
        {
          return (int) ((double) MobileParty.MainParty.MemberRoster.TotalManCount * 0.800000011920929 * (double) this._issueDifficulty);
        }
      }

      public override bool IsRemainingTimeHidden => false;

      private TextObject QuestStartedLog
      {
        get
        {
          TextObject to = new TextObject("{=R98gwuK1}{QUEST_GIVER.LINK} {?QUEST_GIVER.GENDER}lady{?}lord{\\?} of {TARGET_SETTLEMENT} told you that {?QUEST_GIVER.GENDER}she{?}he{\\?} has been having issues with smugglers running between {TARGET_SETTLEMENT} and {ORIGIN_SETTLEMENT}. You promised to track the smugglers down and chase them away from {TARGET_SETTLEMENT}.");
          to.SetCharacterProperties("QUEST_GIVER", this.QuestGiver.CharacterObject);
          to.SetTextVariable("TARGET_SETTLEMENT", this._targetSettlement.EncyclopediaLinkWithName);
          to.SetTextVariable("ORIGIN_SETTLEMENT", this._originSettlement.EncyclopediaLinkWithName);
          return to;
        }
      }

      private TextObject QuestCanceledWarDeclaredLog
      {
        get
        {
          TextObject parent = new TextObject("{=vW6kBki9}Your clan is now at war with {QUEST_GIVER.LINK}'s realm. Your agreement with {QUEST_GIVER.LINK} is canceled.");
          StringHelpers.SetCharacterProperties("QUEST_GIVER", this.QuestGiver.CharacterObject, parent);
          return parent;
        }
      }

      private TextObject QuestCanceledSettlementOwnerChangedLog
      {
        get
        {
          TextObject parent = new TextObject("{=xSaVRIN7}{QUEST_GIVER.LINK} has lost the ownership of {TARGET_CITY}. Your agreement with {QUEST_GIVER.LINK} is canceled.");
          StringHelpers.SetCharacterProperties("QUEST_GIVER", this.QuestGiver.CharacterObject, parent);
          parent.SetTextVariable("TARGET_CITY", this._targetSettlement.EncyclopediaLinkWithName);
          return parent;
        }
      }

      private TextObject QuestFailedLog
      {
        get
        {
          TextObject parent = new TextObject("{=QB4bKAVR}You failed to get rid of the smugglers as you told {QUEST_GIVER.LINK} you would do.");
          StringHelpers.SetCharacterProperties("QUEST_GIVER", this.QuestGiver.CharacterObject, parent);
          return parent;
        }
      }

      private TextObject QuestSuccessWithFightLog
      {
        get
        {
          TextObject parent = new TextObject("{=7N8jdPdV}You got rid of the smugglers as you promised {QUEST_GIVER.LINK} you would do.");
          StringHelpers.SetCharacterProperties("QUEST_GIVER", this.QuestGiver.CharacterObject, parent);
          return parent;
        }
      }

      private TextObject QuestSuccessWithPersuasionLog
      {
        get
        {
          TextObject parent = new TextObject("{=84ZwbJaq}You persuaded the smugglers to move away from {TARGET_SETTLEMENT}. They are now far away from {TARGET_SETTLEMENT} and {QUEST_GIVER.LINK} is satisfied.");
          parent.SetTextVariable("TARGET_SETTLEMENT", this._targetSettlement.Name);
          StringHelpers.SetCharacterProperties("QUEST_GIVER", this.QuestGiver.CharacterObject, parent);
          return parent;
        }
      }

      private TextObject QuestSuccessWithBribeLog
      {
        get
        {
          TextObject parent = new TextObject("{=Ici6us1S}You paid the smugglers to move away from {TARGET_SETTLEMENT}. They are now far away and {QUEST_GIVER.LINK} is satisfied.");
          parent.SetTextVariable("TARGET_SETTLEMENT", this._targetSettlement.Name);
          StringHelpers.SetCharacterProperties("QUEST_GIVER", this.QuestGiver.CharacterObject, parent);
          return parent;
        }
      }

      public override TextObject Title
      {
        get
        {
          TextObject title = new TextObject("{=Gop9Khfk}Smugglers of {TARGET_CITY}");
          title.SetTextVariable("TARGET_CITY", this._targetSettlement.Name);
          return title;
        }
      }

      public SmugglersIssueQuest(
        string questId,
        Hero questGiver,
        Settlement targetSettlement,
        Settlement originSettlement,
        float issueDifficulty,
        CampaignTime duration,
        int rewardGold)
        : base(questId, questGiver, duration, rewardGold)
      {
        this._targetSettlement = targetSettlement;
        this._originSettlement = originSettlement;
        this._issueDifficulty = issueDifficulty;
        this.SetDialogs();
        this.InitializeQuestOnCreation();
      }

      protected override void SetDialogs()
      {
        TextObject npcText1 = new TextObject("{=g8qb3Ame}Thank you.");
        TextObject npcText2 = new TextObject("{=KLkaBjy7}I'm glad you're taking care of those smugglers.");
        this.OfferDialogFlow = DialogFlow.CreateDialogFlow("issue_classic_quest_start").NpcLine(npcText1).Condition((ConversationSentence.OnConditionDelegate) (() => Hero.OneToOneConversationHero == this.QuestGiver)).Consequence(new ConversationSentence.OnConsequenceDelegate(this.QuestAcceptedConsequences)).CloseDialog();
        this.DiscussDialogFlow = DialogFlow.CreateDialogFlow("quest_discuss").NpcLine(npcText2).Condition((ConversationSentence.OnConditionDelegate) (() => Hero.OneToOneConversationHero == this.QuestGiver)).Consequence((ConversationSentence.OnConsequenceDelegate) (() => Campaign.Current.ConversationManager.ConversationEndOneShot += new Action(MapEventHelper.OnConversationEnd))).CloseDialog();
        DialogFlow smugglerPartyDialog = this.GetSmugglerPartyDialog();
        this.AddPersuasionDialogs(smugglerPartyDialog);
        Campaign.Current.ConversationManager.AddDialogFlow(smugglerPartyDialog, (object) this);
      }

      private DialogFlow GetSmugglerPartyDialog()
      {
        TextObject npcText1 = new TextObject("{=EUJaTe2v}Who are you? What do you want from us?");
        TextObject playerText1 = new TextObject("{=4iEQr3il}Halt. You're wanted by the authorities in {TARGET_SETTLEMENT} for smuggling.");
        playerText1.SetTextVariable("TARGET_SETTLEMENT", this._targetSettlement.Name);
        TextObject npcText2 = new TextObject("{=vo8fmqwC}Hey... We're just honest traders here, trying to get by in these hard times.");
        TextObject playerText2 = new TextObject("{=qa3xzdbO}I think not. I'm going to give you one chance to leave this district, and never come back under pain of death.");
        TextObject npcText3 = new TextObject("{=BRaGcALd}Hah! Now why would we do that?");
        TextObject text1 = new TextObject("{=Ga5E2saO}Because it would be easier to work elsewhere.");
        TextObject text2 = new TextObject("{=722uabab}Because if you don't, I'll cut you down right here and now.");
        TextObject npcText4 = new TextObject("{=8dys8maS}Oh is that so? This will be fun.");
        TextObject text3 = new TextObject("{=WwzniBzk}Because I'll pay you. Silver is better than death, isn't it?");
        TextObject npcText5 = new TextObject("{=aABDmDJk}Heh, I like the way you think. Fine. It's become too risky around these parts anyway. You won't see us near {TARGET_SETTLEMENT} again.");
        npcText5.SetTextVariable("TARGET_SETTLEMENT", this._targetSettlement.Name);
        return DialogFlow.CreateDialogFlow("start", 125).NpcLine(npcText1).Condition((ConversationSentence.OnConditionDelegate) (() => this._smugglerParty != null && CharacterObject.OneToOneConversationCharacter == ConversationHelper.GetConversationCharacterPartyLeader(this._smugglerParty.Party))).Consequence((ConversationSentence.OnConsequenceDelegate) (() => this._task = this.GetPersuasionTask())).PlayerLine(playerText1).NpcLine(npcText2).PlayerLine(playerText2).NpcLine(npcText3).BeginPlayerOptions().PlayerOption(text1).GotoDialogState("start_smugglers_persuasion").PlayerOption(text2).NpcLine(npcText4).Consequence((ConversationSentence.OnConsequenceDelegate) (() =>
        {
          EncounterManager.StartPartyEncounter(PartyBase.MainParty, this._smugglerParty.Party);
          Campaign.Current.GameMenuManager.SetNextMenu("encounter");
        })).CloseDialog().PlayerOption(text3).ClickableCondition(new ConversationSentence.OnClickableConditionDelegate(this.BribeCondition)).NpcLine(npcText5).Consequence(new ConversationSentence.OnConsequenceDelegate(this.SucceedQuestWithBribe)).CloseDialog().EndPlayerOptions().CloseDialog();
      }

      private PersuasionTask GetPersuasionTask()
      {
        PersuasionTask persuasionTask = new PersuasionTask(0);
        persuasionTask.FinalFailLine = new TextObject("{=iRarm6f7}We are not going anywhere friend. You're going to have to fight for your silver today.");
        persuasionTask.TryLaterLine = TextObject.Empty;
        persuasionTask.SpokenLine = new TextObject("{=xnT03Yv0}I'm listening.");
        TextObject textObject = new TextObject("{=gtY7QuX0}{QUEST_GIVER.LINK} is on to you. I can guarantee you the time of easy pickings and low risk is over.");
        textObject.SetCharacterProperties("QUEST_GIVER", this.QuestGiver.CharacterObject);
        TextObject line1 = new TextObject("{=T7bMlcj3}Prices in {TARGET_SETTLEMENT} are down these days. Enterprising lads like you can do better elsewhere.");
        line1.SetTextVariable("TARGET_SETTLEMENT", this._targetSettlement.Name);
        TextObject line2 = new TextObject("{=6cbdm02F}Because if you make me angry, you'll wish you were dead long before I actually kill you.");
        PersuasionOptionArgs option1 = new PersuasionOptionArgs(DefaultSkills.Roguery, DefaultTraits.Valor, TraitEffect.Positive, PersuasionArgumentStrength.Hard, true, textObject);
        PersuasionOptionArgs option2 = new PersuasionOptionArgs(DefaultSkills.Trade, DefaultTraits.Calculating, TraitEffect.Positive, PersuasionArgumentStrength.VeryEasy, false, line1);
        PersuasionOptionArgs option3 = new PersuasionOptionArgs(DefaultSkills.Roguery, DefaultTraits.Mercy, TraitEffect.Negative, PersuasionArgumentStrength.VeryHard, false, line2);
        persuasionTask.AddOptionToTask(option1);
        persuasionTask.AddOptionToTask(option2);
        persuasionTask.AddOptionToTask(option3);
        return persuasionTask;
      }

      private void AddPersuasionDialogs(DialogFlow dialog)
      {
        dialog.AddDialogLine("smugglers_persuasion_check_accepted", "start_smugglers_persuasion", "smugglers_persuasion_start_reservation", "{=6P1ruzsC}Maybe...", new ConversationSentence.OnConditionDelegate(this.persuasion_start_with_smugglers_on_condition), new ConversationSentence.OnConsequenceDelegate(this.persuasion_start_with_smugglers_on_consequence), (object) this);
        dialog.AddDialogLine("smugglers_persuasion_rejected", "smugglers_persuasion_start_reservation", "close_window", "{=!}{FAILED_PERSUASION_LINE}", new ConversationSentence.OnConditionDelegate(this.persuasion_failed_with_smugglers_on_condition), new ConversationSentence.OnConsequenceDelegate(this.persuasion_rejected_with_smugglers_on_consequence), (object) this);
        dialog.AddDialogLine("smugglers_persuasion_attempt", "smugglers_persuasion_start_reservation", "smugglers_persuasion_select_option", "{=wM77S68a}What's there to discuss?", (ConversationSentence.OnConditionDelegate) (() => !this.persuasion_failed_with_smugglers_on_condition()), (ConversationSentence.OnConsequenceDelegate) null, (object) this);
        dialog.AddDialogLine("smugglers_persuasion_success", "smugglers_persuasion_start_reservation", "close_window", "{=m61UnySr}Yeah, you make a good point. If you find us, others can too. We will move elsewhere.", new ConversationSentence.OnConditionDelegate(ConversationManager.GetPersuasionProgressSatisfied), new ConversationSentence.OnConsequenceDelegate(this.persuasion_complete_with_smugglers_on_consequence), (object) this, 200);
        DialogFlow dialogFlow1 = dialog;
        ConversationSentence.OnConditionDelegate conditionDelegate1 = new ConversationSentence.OnConditionDelegate(this.smugglers_persuasion_select_option_1_on_condition);
        ConversationSentence.OnConsequenceDelegate consequenceDelegate1 = new ConversationSentence.OnConsequenceDelegate(this.smugglers_persuasion_select_option_1_on_consequence);
        ConversationSentence.OnPersuasionOptionDelegate persuasionOptionDelegate1 = new ConversationSentence.OnPersuasionOptionDelegate(this.smugglers_persuasion_setup_option_1);
        ConversationSentence.OnClickableConditionDelegate clickableConditionDelegate1 = new ConversationSentence.OnClickableConditionDelegate(this.smugglers_persuasion_clickable_option_1_on_condition);
        ConversationSentence.OnPersuasionOptionDelegate persuasionOptionDelegate2 = persuasionOptionDelegate1;
        dialogFlow1.AddPlayerLine("smugglers_persuasion_select_option_1", "smugglers_persuasion_select_option", "smugglers_persuasion_selected_option_response", "{=!}{smugglers_PERSUADE_ATTEMPT_1}", conditionDelegate1, consequenceDelegate1, (object) this, clickableConditionDelegate: clickableConditionDelegate1, persuasionOptionDelegate: persuasionOptionDelegate2);
        DialogFlow dialogFlow2 = dialog;
        ConversationSentence.OnConditionDelegate conditionDelegate2 = new ConversationSentence.OnConditionDelegate(this.smugglers_persuasion_select_option_2_on_condition);
        ConversationSentence.OnConsequenceDelegate consequenceDelegate2 = new ConversationSentence.OnConsequenceDelegate(this.smugglers_persuasion_select_option_2_on_consequence);
        ConversationSentence.OnPersuasionOptionDelegate persuasionOptionDelegate3 = new ConversationSentence.OnPersuasionOptionDelegate(this.smugglers_persuasion_setup_option_2);
        ConversationSentence.OnClickableConditionDelegate clickableConditionDelegate2 = new ConversationSentence.OnClickableConditionDelegate(this.smugglers_persuasion_clickable_option_2_on_condition);
        ConversationSentence.OnPersuasionOptionDelegate persuasionOptionDelegate4 = persuasionOptionDelegate3;
        dialogFlow2.AddPlayerLine("smugglers_persuasion_select_option_2", "smugglers_persuasion_select_option", "smugglers_persuasion_selected_option_response", "{=!}{smugglers_PERSUADE_ATTEMPT_2}", conditionDelegate2, consequenceDelegate2, (object) this, clickableConditionDelegate: clickableConditionDelegate2, persuasionOptionDelegate: persuasionOptionDelegate4);
        DialogFlow dialogFlow3 = dialog;
        ConversationSentence.OnConditionDelegate conditionDelegate3 = new ConversationSentence.OnConditionDelegate(this.smugglers_persuasion_select_option_3_on_condition);
        ConversationSentence.OnConsequenceDelegate consequenceDelegate3 = new ConversationSentence.OnConsequenceDelegate(this.smugglers_persuasion_select_option_3_on_consequence);
        ConversationSentence.OnPersuasionOptionDelegate persuasionOptionDelegate5 = new ConversationSentence.OnPersuasionOptionDelegate(this.smugglers_persuasion_setup_option_3);
        ConversationSentence.OnClickableConditionDelegate clickableConditionDelegate3 = new ConversationSentence.OnClickableConditionDelegate(this.smugglers_persuasion_clickable_option_3_on_condition);
        ConversationSentence.OnPersuasionOptionDelegate persuasionOptionDelegate6 = persuasionOptionDelegate5;
        dialogFlow3.AddPlayerLine("smugglers_persuasion_select_option_3", "smugglers_persuasion_select_option", "smugglers_persuasion_selected_option_response", "{=!}{smugglers_PERSUADE_ATTEMPT_3}", conditionDelegate3, consequenceDelegate3, (object) this, clickableConditionDelegate: clickableConditionDelegate3, persuasionOptionDelegate: persuasionOptionDelegate6);
        dialog.AddDialogLine("smugglers_persuasion_select_option_reaction", "smugglers_persuasion_selected_option_response", "smugglers_persuasion_start_reservation", "{=!}{PERSUASION_REACTION}", new ConversationSentence.OnConditionDelegate(this.smugglers_persuasion_selected_option_response_on_condition), new ConversationSentence.OnConsequenceDelegate(this.smugglers_persuasion_selected_option_response_on_consequence), (object) this);
      }

      private void persuasion_start_with_smugglers_on_consequence()
      {
        ConversationManager.StartPersuasion(2f, 1f, 0.0f, 2f, 2f, 0.0f, PersuasionDifficulty.MediumHard);
      }

      private bool persuasion_start_with_smugglers_on_condition()
      {
        return this._smugglerParty != null && CharacterObject.OneToOneConversationCharacter == ConversationHelper.GetConversationCharacterPartyLeader(this._smugglerParty.Party);
      }

      private bool smugglers_persuasion_selected_option_response_on_condition()
      {
        PersuasionOptionResult optionResult = ConversationManager.GetPersuasionChosenOptions().Last<Tuple<PersuasionOptionArgs, PersuasionOptionResult>>().Item2;
        MBTextManager.SetTextVariable("PERSUASION_REACTION", PersuasionHelper.GetDefaultPersuasionOptionReaction(optionResult), false);
        if (optionResult == PersuasionOptionResult.CriticalFailure)
          this._task.BlockAllOptions();
        return true;
      }

      private void smugglers_persuasion_selected_option_response_on_consequence()
      {
        Tuple<PersuasionOptionArgs, PersuasionOptionResult> tuple = ConversationManager.GetPersuasionChosenOptions().Last<Tuple<PersuasionOptionArgs, PersuasionOptionResult>>();
        float difficulty = Campaign.Current.Models.PersuasionModel.GetDifficulty(PersuasionDifficulty.MediumHard);
        float moveToNextStageChance;
        float blockRandomOptionChance;
        Campaign.Current.Models.PersuasionModel.GetEffectChances(tuple.Item1, out moveToNextStageChance, out blockRandomOptionChance, difficulty);
        this._task.ApplyEffects(moveToNextStageChance, blockRandomOptionChance);
      }

      private bool smugglers_persuasion_select_option_1_on_condition()
      {
        if (this._task.Options.Count <= 0)
          return false;
        TextObject text = new TextObject("{=bSo9hKwr}{PERSUASION_OPTION_LINE} {SUCCESS_CHANCE}");
        text.SetTextVariable("SUCCESS_CHANCE", PersuasionHelper.ShowSuccess(this._task.Options.ElementAt<PersuasionOptionArgs>(0), false));
        text.SetTextVariable("PERSUASION_OPTION_LINE", this._task.Options.ElementAt<PersuasionOptionArgs>(0).Line);
        MBTextManager.SetTextVariable("smugglers_PERSUADE_ATTEMPT_1", text, false);
        return true;
      }

      private bool smugglers_persuasion_select_option_2_on_condition()
      {
        if (this._task.Options.Count <= 1)
          return false;
        TextObject text = new TextObject("{=bSo9hKwr}{PERSUASION_OPTION_LINE} {SUCCESS_CHANCE}");
        text.SetTextVariable("SUCCESS_CHANCE", PersuasionHelper.ShowSuccess(this._task.Options.ElementAt<PersuasionOptionArgs>(1), false));
        text.SetTextVariable("PERSUASION_OPTION_LINE", this._task.Options.ElementAt<PersuasionOptionArgs>(1).Line);
        MBTextManager.SetTextVariable("smugglers_PERSUADE_ATTEMPT_2", text, false);
        return true;
      }

      private bool smugglers_persuasion_select_option_3_on_condition()
      {
        if (this._task.Options.Count <= 2)
          return false;
        TextObject text = new TextObject("{=bSo9hKwr}{PERSUASION_OPTION_LINE} {SUCCESS_CHANCE}");
        text.SetTextVariable("SUCCESS_CHANCE", PersuasionHelper.ShowSuccess(this._task.Options.ElementAt<PersuasionOptionArgs>(2), false));
        text.SetTextVariable("PERSUASION_OPTION_LINE", this._task.Options.ElementAt<PersuasionOptionArgs>(2).Line);
        MBTextManager.SetTextVariable("smugglers_PERSUADE_ATTEMPT_3", text, false);
        return true;
      }

      private void smugglers_persuasion_select_option_1_on_consequence()
      {
        if (this._task.Options.Count <= 0)
          return;
        this._task.Options[0].BlockTheOption(true);
      }

      private void smugglers_persuasion_select_option_2_on_consequence()
      {
        if (this._task.Options.Count <= 1)
          return;
        this._task.Options[1].BlockTheOption(true);
      }

      private void smugglers_persuasion_select_option_3_on_consequence()
      {
        if (this._task.Options.Count <= 2)
          return;
        this._task.Options[2].BlockTheOption(true);
      }

      private bool persuasion_failed_with_smugglers_on_condition()
      {
        if (!this._task.Options.All<PersuasionOptionArgs>((Func<PersuasionOptionArgs, bool>) (x => x.IsBlocked)) || ConversationManager.GetPersuasionProgressSatisfied())
          return false;
        MBTextManager.SetTextVariable("FAILED_PERSUASION_LINE", this._task.FinalFailLine, false);
        return true;
      }

      private PersuasionOptionArgs smugglers_persuasion_setup_option_1()
      {
        return this._task.Options.ElementAt<PersuasionOptionArgs>(0);
      }

      private PersuasionOptionArgs smugglers_persuasion_setup_option_2()
      {
        return this._task.Options.ElementAt<PersuasionOptionArgs>(1);
      }

      private PersuasionOptionArgs smugglers_persuasion_setup_option_3()
      {
        return this._task.Options.ElementAt<PersuasionOptionArgs>(2);
      }

      private bool smugglers_persuasion_clickable_option_1_on_condition(out TextObject hintText)
      {
        hintText = new TextObject("{=9ACJsI6S}Blocked");
        if (this._task.Options.Count <= 0)
          return false;
        hintText = this._task.Options.ElementAt<PersuasionOptionArgs>(0).IsBlocked ? hintText : TextObject.Empty;
        return !this._task.Options.ElementAt<PersuasionOptionArgs>(0).IsBlocked;
      }

      private bool smugglers_persuasion_clickable_option_2_on_condition(out TextObject hintText)
      {
        hintText = new TextObject("{=9ACJsI6S}Blocked");
        if (this._task.Options.Count <= 1)
          return false;
        hintText = this._task.Options.ElementAt<PersuasionOptionArgs>(1).IsBlocked ? hintText : TextObject.Empty;
        return !this._task.Options.ElementAt<PersuasionOptionArgs>(1).IsBlocked;
      }

      private bool smugglers_persuasion_clickable_option_3_on_condition(out TextObject hintText)
      {
        hintText = new TextObject("{=9ACJsI6S}Blocked");
        if (this._task.Options.Count <= 2)
          return false;
        hintText = this._task.Options.ElementAt<PersuasionOptionArgs>(2).IsBlocked ? hintText : TextObject.Empty;
        return !this._task.Options.ElementAt<PersuasionOptionArgs>(2).IsBlocked;
      }

      private void persuasion_rejected_with_smugglers_on_consequence()
      {
        PlayerEncounter.LeaveEncounter = false;
        ConversationManager.EndPersuasion();
      }

      private void persuasion_complete_with_smugglers_on_consequence()
      {
        PlayerEncounter.LeaveEncounter = true;
        ConversationManager.EndPersuasion();
        Campaign.Current.ConversationManager.ConversationEndOneShot += (Action) (() => this.SucceedQuest(this.QuestSuccessWithPersuasionLog));
      }

      private bool BribeCondition(out TextObject explanation)
      {
        if (Hero.MainHero.Gold >= this.BribeAmount)
        {
          explanation = new TextObject("{=FebKjriO}You will give {BRIBE_AMOUNT} denars.");
          explanation.SetTextVariable("BRIBE_AMOUNT", this.BribeAmount);
          return true;
        }
        explanation = new TextObject("{=Xy4brTbf}You don't have {BRIBE_AMOUNT} denars.");
        explanation.SetTextVariable("BRIBE_AMOUNT", this.BribeAmount);
        return false;
      }

      private void QuestAcceptedConsequences()
      {
        this.StartQuest();
        this.AddLog(this.QuestStartedLog);
        this._smugglerParty = this.CreateSmugglerParty();
        this.AddTrackedObject((ITrackableCampaignObject) this._targetSettlement);
        this.AddTrackedObject((ITrackableCampaignObject) this._originSettlement);
      }

      private MobileParty CreateSmugglerParty()
      {
        TextObject name = new TextObject("{=3dhAfC4k}Smugglers of {ORIGIN_SETTLEMENT}");
        name.SetTextVariable("ORIGIN_SETTLEMENT", this._originSettlement.Name);
        TroopRoster.CreateDummyTroopRoster();
        TroopRoster.CreateDummyTroopRoster();
        string mountStringId;
        string harnessStringId;
        this.GetAdditionalVisualsForParty(this._originSettlement.Culture, out mountStringId, out harnessStringId);
        Settlement nearestHideoutSettlement = SettlementHelper.FindNearestHideout();
        int troopLimit = (int) MathF.Clamp((float) MathF.Ceiling((float) MobileParty.MainParty.MemberRoster.TotalManCount * 0.8f), 15f, 35f);
        float customPartyBaseSpeed = MobileParty.MainParty.Speed * 1.1f;
        MobileParty questParty = CustomPartyComponent.CreateQuestParty(this._originSettlement.GatePosition, 0.1f, this._originSettlement, name, Clan.BanditFactions.FirstOrDefault<Clan>((Func<Clan, bool>) (faction => faction.Culture == nearestHideoutSettlement.Culture)), this._originSettlement.Culture.CaravanPartyTemplate, (Hero) null, troopLimit, mountStringId, harnessStringId, customPartyBaseSpeed, true);
        CharacterObject character = MBObjectManager.Instance.GetObject<CharacterObject>("nervous_caravanmaster_" + (object) MBRandom.RandomInt(1, 4));
        questParty.MemberRoster.AddToCounts(character, 1, true);
        this.GiveGoodsToParty(questParty);
        this.InitializePartyState(questParty);
        questParty.SetPartyUsedByQuest(true);
        return questParty;
      }

      private void GetAdditionalVisualsForParty(
        CultureObject culture,
        out string mountStringId,
        out string harnessStringId)
      {
        if (culture.StringId == "aserai" || culture.StringId == "khuzait")
        {
          mountStringId = "camel";
          harnessStringId = (double) MBRandom.RandomFloat > 0.5 ? "camel_saddle_a" : "camel_saddle_b";
        }
        else
        {
          mountStringId = "mule";
          harnessStringId = (double) MBRandom.RandomFloat > 0.5 ? "mule_load_a" : ((double) MBRandom.RandomFloat > 0.5 ? "mule_load_b" : "mule_load_c");
        }
      }

      private void GiveGoodsToParty(MobileParty mobileParty)
      {
        int num1 = MathF.Ceiling((float) (400.0 + 3000.0 * (double) this._issueDifficulty));
        ItemObject itemObject = MBObjectManager.Instance.GetObject<ItemObject>(this._possibleSmuggledItems.GetRandomElement<string>());
        int num2 = itemObject.Value;
        int number = num1 / num2;
        mobileParty.ItemRoster.AddToCounts(itemObject, number);
        mobileParty.ItemRoster.AddToCounts(MBObjectManager.Instance.GetObject<ItemObject>("grain"), MathF.Ceiling((float) (30.0 + 20.0 * (double) this._issueDifficulty)));
      }

      private void InitializePartyState(MobileParty mobileParty)
      {
        TextObject name = new TextObject("{=GTnVcUz9}Smugglers' Party");
        mobileParty.InitializeMobilePartyAtPosition(new TroopRoster(mobileParty.Party), new TroopRoster(mobileParty.Party), this._originSettlement.GatePosition);
        mobileParty.SetCustomName(name);
        mobileParty.Ai.SetDoNotMakeNewDecisions(true);
        mobileParty.IgnoreByOtherPartiesTill(CampaignTime.Never);
        mobileParty.SetCustomHomeSettlement(this._originSettlement);
        SetPartyAiAction.GetActionForVisitingSettlement(mobileParty, this._targetSettlement);
      }

      protected override void OnTimedOut() => this.FailQuest();

      private void SucceedQuestWithBribe()
      {
        PlayerEncounter.LeaveEncounter = true;
        GiveGoldAction.ApplyForQuestBetweenCharacters(Hero.MainHero, (Hero) null, this.BribeAmount);
        this.SucceedQuest(this.QuestSuccessWithBribeLog);
      }

      private void SucceedQuest(TextObject log)
      {
        this.AddLog(log);
        this.RemoveTrackedObject((ITrackableCampaignObject) this._targetSettlement);
        this.RemoveTrackedObject((ITrackableCampaignObject) this._originSettlement);
        this.RelationshipChangeWithQuestGiver = 10;
        this._targetSettlement.Town.Security += 10f;
        GiveGoldAction.ApplyForQuestBetweenCharacters(this.QuestGiver, Hero.MainHero, this.RewardGold);
        if (this._smugglerParty != null)
          DestroyPartyAction.Apply((PartyBase) null, this._smugglerParty);
        this.CompleteQuestWithSuccess();
      }

      private void FailQuest()
      {
        TraitLevelingHelper.OnIssueFailed(Hero.MainHero, new Tuple<TraitObject, int>[2]
        {
          new Tuple<TraitObject, int>(DefaultTraits.Honor, -50),
          new Tuple<TraitObject, int>(DefaultTraits.Valor, -50)
        });
        this.RelationshipChangeWithQuestGiver = -10;
        this.RemoveTrackedObject((ITrackableCampaignObject) this._targetSettlement);
        this.RemoveTrackedObject((ITrackableCampaignObject) this._originSettlement);
        this.CompleteQuestWithFail(this.QuestFailedLog);
        DestroyPartyAction.Apply((PartyBase) null, this._smugglerParty);
      }

      protected override void RegisterEvents()
      {
        CampaignEvents.OnSettlementOwnerChangedEvent.AddNonSerializedListener((object) this, new Action<Settlement, bool, Hero, Hero, Hero, ChangeOwnerOfSettlementAction.ChangeOwnerOfSettlementDetail>(this.OnSettlementOwnerChanged));
        CampaignEvents.WarDeclared.AddNonSerializedListener((object) this, new Action<IFaction, IFaction, DeclareWarAction.DeclareWarDetail>(this.OnWarDeclared));
        CampaignEvents.OnClanChangedKingdomEvent.AddNonSerializedListener((object) this, new Action<Clan, Kingdom, Kingdom, ChangeKingdomAction.ChangeKingdomActionDetail, bool>(this.OnClanChangedKingdom));
        CampaignEvents.HourlyTickPartyEvent.AddNonSerializedListener((object) this, new Action<MobileParty>(this.OnHourlyTickParty));
        CampaignEvents.MapEventEnded.AddNonSerializedListener((object) this, new Action<MapEvent>(this.OnMapEventEnded));
      }

      private void OnMapEventEnded(MapEvent mapEvent)
      {
        if (!mapEvent.IsPlayerMapEvent || !mapEvent.InvolvedParties.Contains<PartyBase>(this._smugglerParty.Party))
          return;
        if (mapEvent.WinningSide == mapEvent.PlayerSide)
          this.SucceedQuest(this.QuestSuccessWithFightLog);
        else
          this.FailQuest();
      }

      private void OnHourlyTickParty(MobileParty mobileParty)
      {
        if (mobileParty != this._smugglerParty || mobileParty.CurrentSettlement == null)
          return;
        if (this._smugglerSettlementWaitCounter >= 4)
        {
          this._smugglerSettlementWaitCounter = 0;
          Settlement settlement = mobileParty.CurrentSettlement == this._targetSettlement ? this._originSettlement : this._targetSettlement;
          SetPartyAiAction.GetActionForVisitingSettlement(mobileParty, settlement);
        }
        else
          ++this._smugglerSettlementWaitCounter;
      }

      private void OnClanChangedKingdom(
        Clan clan,
        Kingdom oldKingdom,
        Kingdom newKingdom,
        ChangeKingdomAction.ChangeKingdomActionDetail detail,
        bool showNotification = true)
      {
        if (clan != this.QuestGiver.Clan || !newKingdom.IsAtWarWith((IFaction) Clan.PlayerClan))
          return;
        this.CompleteQuestWithCancel(this.QuestCanceledWarDeclaredLog);
      }

      private void OnWarDeclared(
        IFaction faction1,
        IFaction faction2,
        DeclareWarAction.DeclareWarDetail declareWarDetail)
      {
        QuestHelper.CheckWarDeclarationAndFailOrCancelTheQuest((QuestBase) this, faction1, faction2, declareWarDetail, this.QuestCanceledWarDeclaredLog, this.QuestCanceledWarDeclaredLog);
      }

      private void OnSettlementOwnerChanged(
        Settlement settlement,
        bool openToClaim,
        Hero newOwner,
        Hero oldOwner,
        Hero capturerHero,
        ChangeOwnerOfSettlementAction.ChangeOwnerOfSettlementDetail detail)
      {
        if (settlement != this._targetSettlement)
          return;
        this.CompleteQuestWithCancel(this.QuestCanceledSettlementOwnerChangedLog);
      }

      protected override void InitializeQuestOnGameLoad() => this.SetDialogs();

      protected override void HourlyTick()
      {
      }
    }

    public class SmugglersIssueTypeDefiner : SaveableTypeDefiner
    {
      public SmugglersIssueTypeDefiner()
        : base(585960)
      {
      }

      protected override void DefineClassTypes()
      {
        this.AddClassDefinition(typeof (SmugglersIssueBehavior.SmugglersIssue), 1);
        this.AddClassDefinition(typeof (SmugglersIssueBehavior.SmugglersIssueQuest), 2);
      }
    }
  }
}
